﻿<?php
class  publicControl extends Control{
	function login(){
	$this->display();
	}
 function logintype(){//登录验证
		$username=$_POST["username"];
		$password=md5($_POST["password"]);
		$db=M("user");
		$row=$db->where("username='$username'")->find();
		if(!$db->get_affected_rows()){
			echo 1;
			return false;
		}else{
			$pas=$db->where("password='$password'")->find();
			if($db->get_affected_rows()){
				echo 3;
		$db=K("roleview");
		$row=$db->join("user_role")->field("rid")->where("username='$username'")->find();
		$_SESSION['rid']=$row['rid'];
			$_SESSION["username"]=$_POST["username"];
			}else{
			    echo 2;
		            return false;
	}
	}	
	}
 function adduser(){//注册账号
	 $this->display();
	 	}
 function reg(){//帐号验证
 	C("debug",0);
        $username=$_POST['data'];
		$reg='/^[a-zA-Z]{1}\w{5,19}$/';
		//$str='ssss';
		$r=preg_match($reg,$username);
		$db=M("user");
		$row=$db->findall();
         $row=$db->where("username='$username'")->findall();
         if($db->get_affected_rows()){//如果有结果就代表用户名已经存在
            echo 2;
         }else if($r){//如果长度符合的划就输出1
		 echo 1;         
         }else{//不符合长度的话输出3
		  echo 3;
	 } 
	}
   function add(){
           $db=M("user");
          /* foreach ($_POST as $v){
                if(empty($v)){
                   $this->error("资料有误请确认后提交");
                  return false;
         }                     
         }*/
            $_POST['password']=md5($_POST['password']);
            if($db->add()){
			$_SESSION["username"]=$_POST["username"];
               $this->go("admin/index/index");
            }else{
               $this->error("资料有误请确认后提交");
        }
            
        }  
}




?>